// KMD5.cpp: implementation of the KMD5 class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "KMD5.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

KMD5::KMD5()
{

}

KMD5::~KMD5()
{

}

void KMD5::EncryptByMD5(const CString &strOrialText, CString &strEncryptedText)
{
	Update( (BYTE*)(LPCTSTR)strOrialText, (UINT)strOrialText.GetLength() );
	Finalize();

	char *pszBufEncryptedText= strEncryptedText.GetBuffer( 256 +1 );
	char chEach[10];
	memset(pszBufEncryptedText,0,256);
	memset(chEach, 0, 10);

	for (int nCount = 0; nCount < 8; nCount++)
	{
		sprintf(chEach, "%02x", Digest()[nCount]);
		strncat( pszBufEncryptedText, chEach, sizeof(chEach) );
	}

	strEncryptedText.ReleaseBuffer();
}
